//////////////////////////////////////////////////////////page_parkRecommend//////////////////////////
$(document).on("pageInit", "#page_parkRecommend", function(e, pageId, $page) {
    my.givetitle('泊车确认');
    setTimeout(function(){
    	$.showPreloader()
    },1)

			        var carListsort=''
                    var pageNow=1
			        $('.parkRecoLocal').val(sessionStorage.flight_endPlace)      //parkIndex航班信息返回
			        $('[name=park_place]').val(sessionStorage.flight_endPlace_id)//parkIndex航班信息返回
			        var key=my.get_key(my.getCookie('token'))
					var info = {
						user_id: my.getCookie('id'),
						car_place:$('[name=park_place]').val(),
						start_time:sessionStorage.parking_starttime,
						end_time:sessionStorage.parking_endtime,
						scb: '',
						seat: '',
						city: '',
						page: 1,
						rows: 100,
						brandid: '',
						carsid: '',

					}
					console.log(info)
					info = my.cryptoASEencrypt(JSON.stringify(info), key)
					$.ajax({
						url: api.selectvehicle,
						type: 'post',
						async: true,
						data: {
							'api_value': info
						},
						error: function() {
							$.hidePreloader()
							$.toast("提交失败，请重试！");
						},
						success: function(data) {
							$.hidePreloader()
							if(data.match("err_code") != null) {
								switch(JSON.parse(data).err_code) {
									case 40003:
										my.tokenExpire()
										break;
									default:
										$.alert(JSON.parse(data).err_msg)

								}
							} else {
								data = JSON.parse(data)
								data = JSON.parse(my.cryptoASEdencrypt(data.data, key))
								carListsort = data.car_list
								console.log(carListsort)
								carListsort.sort(function(x, y) {
										return x.work_day_price - y.work_day_price
									})
									//sessionStorage.rentalCal_list=JSON.stringify(data.car_list)
								$('header').show()
								$('.carlist').show()
								$('.carR-car-list ul').empty()
//								if(data.car_list.length < 10) {
//									$('.parkReco-more').hide();
//								}
								for(i = 0; i < data.car_list.length; i++) {

									var usercar_nickname = data.car_list[i].usercar_nickname ? data.car_list[i].usercar_nickname.substr(0, 2) + '***' : '未填写'
									var speed_changing_box
									if(data.car_list[i].speed_changing_box == 1) {
										speed_changing_box = '手动'
									} else if(data.car_list[i].speed_changing_box == 2) {
										speed_changing_box = '自动'
									}
									switch(+data.car_list[i].seat) {
										case 1:
											seat = "2座";
											break;
										case 2:
											seat = "5座";
											break;
										case 3:
											seat = "7座";
											break;
										case 4:
											seat = "7座以上";
											break;
									}
									var list = '<li title="' + i + '" id="' + data.car_list[i].usercar_id + '"><div><img style="height: 8rem;max-width: 100%;" src="' + config.url_car + data.car_list[i].models_logo + '"></div><div>' +
										data.car_list[i].brand_chinese_name + '/' + data.car_list[i].models_name + '</div><div><span>' +
										data.car_list[i].work_day_price + ' 元起</span><span style="float: right;color: #fff;"></span><div class="clear"></div></div>' +
										'<div class="qcxq">' + usercar_nickname + '/' + data.car_list[i].usercar_color + '/' + speed_changing_box + '/行李箱' +
										data.car_list[i].trunk_capacity + 'L/' + seat + '</div></li>'
									$('.carR-car-list ul').append(list)

								}
								$('.carR-car-list ul').on('click','li',function() {
									var id = $(this).attr('title')
									sessionStorage.rentalCalDetails = JSON.stringify(data.car_list[id])
									sessionStorage.carDetails_carid = data.car_list[id].usercar_id
									sessionStorage.car_place=$('[name=park_place]').val()
      					            sessionStorage.rangTimeStart=$('[name=parking_starttime]').val()
      					            sessionStorage.rangTimeEnd=$('[name=parking_endtime]').val()
									$.router.load(carDetailsUrl,true)
                                    //$.router.load(carDetailsUrl,true);
								})

							}
						}
				})


			$("#pr-parking_starttime").datetimePickerCustom({

                        toolbarTemplate: '<header class="bar bar-nav">\
        <button class="button button-link pull-left script_swapend" onclick="$(\'.start_parkIndex_start\').datetimePickerCustom(\'close\');$(\'.end_parkIndex_end\').datetimePickerCustom(\'open\');">结束时间</button>\
  <button class="button button-link pull-right close-picker">确定</button>\
  <h1 class="title">请设置开始时间</h1> </header>',

                        customValue:sessionStorage.parking_starttime,
                        customMinuteInterval:4,//指定分钟的间隔方式，此处整型指定分钟间隔的分母，如指定4，则为1/4，即分钟选择会变成00,15,30,45，该值不能为0
                        hideMinute:false,//是否隐藏分钟,隐藏分钟则控件值为yyyy-MM-dd hh
                        hideHour:false,//是否隐藏小时,隐藏小时则控件值为yyyy-MM-dd

                        hourLimit:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]//指定小时限制，只有数组中出现的小时才能被选择

                    });
          $("#pr-parking_endtime").datetimePickerCustom({

                        toolbarTemplate: '<header class="bar bar-nav">\
        <button class="button button-link pull-left script_swapend" onclick="$(\'.start_parkIndex_start\').datetimePickerCustom(\'close\');$(\'.end_parkIndex_end\').datetimePickerCustom(\'open\');">结束时间</button>\
  <button class="button button-link pull-right close-picker">确定</button>\
  <h1 class="title">请设置开始时间</h1> </header>',

                        customValue:sessionStorage.parking_endtime,
                        customMinuteInterval:4,//指定分钟的间隔方式，此处整型指定分钟间隔的分母，如指定4，则为1/4，即分钟选择会变成00,15,30,45，该值不能为0
                        hideMinute:false,//是否隐藏分钟,隐藏分钟则控件值为yyyy-MM-dd hh
                        hideHour:false,//是否隐藏小时,隐藏小时则控件值为yyyy-MM-dd

                        hourLimit:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]//指定小时限制，只有数组中出现的小时才能被选择

                    });

					$("[name=parking_starttime]").change(function(){
						sessionStorage.parking_starttime=$(this).val()+":00"
					})
					$("[name=parking_endtime]").change(function(){
						sessionStorage.parking_endtime=$(this).val()+":00"
					})
					//加载更多
				    $('.parkReco-more').click(function(){
				    $.showPreloader()
                    pageNow=Math.ceil($('.carR-car-list ul li').length/10+0.01)
                    setTimeout(function() {
                  var info = {
						user_id: my.getCookie('id'),
						car_place:$('[name=park_place]').val(),
						start_time:sessionStorage.parking_starttime,
						end_time:sessionStorage.parking_endtime,
						scb: '',
						seat: '',
						city: '',
						page: 1,
						rows: 100,
						brandid: '',
						carsid: '',

					}
                  console.log(info)
      				        info=my.cryptoASEencrypt(JSON.stringify(info),key)
      				        $.ajax({
      					       url:api.selectvehicle,
      					       type: 'post',
      					       async:false,
      					       data:{'api_value':info},
      					       error:function(){
      					       	   $.hidePreloader()
      					       	   $('#carRental-submit').removeClass('active_btn')
      					       	   $.toast("提交失败，请重试！");},
      					       success:function(data){
      					       	   $.hidePreloader()
      						     if(data.match("err_code")!=null){
      						     	$('.carR-car-list ul').empty()
      							    switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.tokenExpire()
      									   break;
      									default:
      									   $.alert(JSON.parse(data).err_msg)
      								}
      						     }else{
      							        data=JSON.parse(data)
      								    data=JSON.parse(my.cryptoASEdencrypt(data.data,key))
      								    console.log(data)
      								    //carListsort=carListsort.concat(data.car_list)
      								   // carListsort.sort(function(x,y){return x.work_day_price-y.work_day_price})

      	    	   	                       if(data.car_list.length!=0){
      	    	   		                       if(pageNow==1){
      	    	   		                               $('.carR-car-list ul').empty()
      	    	   		                          }
      	    	   		                   for(i=0;i<data.car_list.length;i++){
      				                    	  var usercar_nickname=data.car_list[i].usercar_nickname.substr(0,2)+'***'
      				                    	  var speed_changing_box
      				                    	  if(data.car_list[i].speed_changing_box==1){
      				                    		speed_changing_box='手动'
      				                    	    }else if(data.car_list[i].speed_changing_box==2){
      				                    		speed_changing_box='自动'
      				                    	    }
      				                    	    switch(+data.car_list[i].seat){
      				                    		case 1:
      				                    		seat="2座";
      				                    		break;
      				                    		case 2:
      				                    		seat="5座";
      				                    		break;
      				                    		case 3:
      				                    		seat="7座";
      				                    		break;
      				                    		case 4:
      				                    		seat="7座以上";
      				                    		break;
      				                    	}
      				                            var list='<li title="'+i+'" id="'+data.car_list[i].usercar_id+'"><div><img style="height: 8rem;max-width: 100%;" src="'+config.url_car+data.car_list[i].models_logo+'"></div><div>'
		                                          +data.car_list[i].brand_chinese_name+'/'+data.car_list[i].models_name+'</div><div><span>'
		                                          +data.car_list[i].work_day_price+' 元起</span><span style="float: right;color: #fff;"></span><div class="clear"></div></div>'
		                                          +'<div class="qcxq">'+usercar_nickname+'/'+data.car_list[i].usercar_color+'/'+speed_changing_box+'/行李箱'
                                                  +data.car_list[i].trunk_capacity+'L/'+seat+'</div></li>'
      				                            $('.carR-car-list ul').append(list)

      				                       }

                                 $('.carR-car-list ul').on('click','li',function() {
									  var id = $(this).attr('title')
									  sessionStorage.rentalCalDetails = JSON.stringify(data.car_list[id])
									  sessionStorage.carDetails_carid = data.car_list[id].usercar_id
									  sessionStorage.car_place=$('[name=park_place]').val()
      					              sessionStorage.rangTimeStart=$('[name=parking_starttime]').val()
      					              sessionStorage.rangTimeEnd=$('[name=parking_endtime]').val()
									  //$.router.loadPage("carDetails.html");
                                               $.router.load(carDetailsUrl,true);
								 })
      	    	                           }else{
      	    	     	                       $.alert('没有了')
      	    	                            }

      							}
      					    }
      			         })
      			    }, 2000);
      			  })
//             //加载更多结束

//           //门店
//               $('.parkRecoLocal').click(function(){
//               	$('.parkRcom_parkPlace').show()
//               })
//               var parkRcom_parkPlace=JSON.parse(sessionStorage.parkPlace_parkReco)
//                   for(var i=0;i<parkRcom_parkPlace.to_store.length;i++){
//                   	 var list='<div name='+parkRcom_parkPlace.to_store[i].stores_id+'>'+parkRcom_parkPlace.to_store[i].stores_name+'</div>'
//                   	 $('.parkRcom_parkPlace').append(list)
//                   }
//                   $('.parkRcom_parkPlace div').click(function(){
//                   	$('.parkRecoLocal').val($(this).text())
//                   	$('[name=park_place]').val($(this).attr('name'))
//                   	$('.parkRcom_parkPlace').hide()
//                   })
              //门店
})